# -*- coding: utf-8 -*-
'''
Created on 2018年6月18日
@author: liaolzl
'''
#1.urljoin
from urllib.parse import urljoin
print(urljoin('http://www.baidu.com','FAQ.html'))
print(urljoin('http://www.baidu.com','https://cuiqingcai.com/FAQ.html'))
print(urljoin('http://www.baidu.com/about.html','https://cuiqingcai.com/FAQ.html'))
print(urljoin('http://www.baidu.com','?category=2#comment'))

#2.urlencode可以将字典对象转换成get请求参数
#get请求参数格式：？+参数+&+参数+&
from urllib.parse import urlencode
params = {
    'name':'germey',
    'age':22
}
base_url = 'http://www.baidu.com?'
url = base_url + urlencode(params)
print(url)